package com.shaozi.nc.utils;

import java.util.ArrayList;
import java.util.List;

import com.shaozi.data.mq.business.bean.MqTargetUserBean;
import com.shaozi.nc.data.model.OperationModel;
import com.shaozi.nc.data.model.SecretaryModel;
import com.shaozi.nc.mq.bean.operation.OperationMsgBean;

public class OperationHelper {
	public static OperationMsgBean toMsgBean(OperationModel peration, String userId) {
		if ((peration.getUsers() == null) || (peration.getUsers().isEmpty()))
			return null;
		for (MqTargetUserBean user : peration.getUsers()) {
			if (user.getUserId() != null && user.getUserId().equals(userId)) {
				OperationMsgBean msgBean = new OperationMsgBean();
				initSecretaryMsgBean(msgBean, peration, user);
				return msgBean;
			}
		}
		return null;
	}

	public static List<OperationMsgBean> toMsgBean(OperationModel model) {
		if ((model.getUsers() == null) || (model.getUsers().isEmpty()))
			return null;
		List<OperationMsgBean> ret = new ArrayList<OperationMsgBean>();
		for (MqTargetUserBean user : model.getUsers()) {
			OperationMsgBean msgBean = new OperationMsgBean();
			initSecretaryMsgBean(msgBean, model, user);
			ret.add(msgBean);
		}
		return ret;
	}

	public static List<OperationMsgBean> toMsgBean(SecretaryModel model) {
		if ((model.getUsers() == null) || (model.getUsers().isEmpty()))
			return null;
		List<OperationMsgBean> ret = new ArrayList<OperationMsgBean>();
		for (MqTargetUserBean user : model.getUsers()) {
			OperationMsgBean msgBean = new OperationMsgBean();
			initSecretaryMsgBean(msgBean, model, user);
			ret.add(msgBean);
		}
		return ret;
	}

	private static void initSecretaryMsgBean(OperationMsgBean msgBean, SecretaryModel model, MqTargetUserBean user) {
		SecretaryHelper.commonInitSecretaryMsgBean(msgBean, model, user);
		msgBean.setOperationId(model.getId());
	}

	private static void initSecretaryMsgBean(OperationMsgBean msgBean, OperationModel model, MqTargetUserBean user) {
		SecretaryHelper.commonInitSecretaryMsgBean(msgBean, model, user);
		msgBean.setOperationId(model.getId());
	}
}
